package com.wl.eb.controller;

import com.wl.eb.module.EbNews;
import com.wl.eb.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("/news")
public class NewsController {

    @Resource
    private NewsService newsService;
    @RequestMapping("/detail")
    public String detail(Model model, int newsId) throws Exception{
        //调用service根据newsId查询该商品的详情
        EbNews newsDetail = newsService.detail(newsId);
        if(newsDetail==null){
            throw new RuntimeException("查询的新闻不存在！！");}
        //将详情数据绑定到MOdel中
        model.addAttribute("detail",newsDetail);
        //返回view
        return "news-view";//news-view.html
    }

}
